package treemodel;

import exception.InvalidHtmlDocumentException;
import treeview.NodeView;
import treeview.container.VerticalContainer;
import document.Context;

import java.util.ArrayList;

/**
 * Created by Pavel Nikolaev
 */
public abstract class Container implements Node {
    protected ArrayList<Node> myNodes;

    public Container() {
        this.myNodes = new ArrayList<Node>();
    }

    public void add(Node node) {
        myNodes.add(node);
    }

    public void prepareForWrapping() {
        for (Node node : myNodes) node.prepareForWrapping();
    }

    public NodeView createView(Context context) {
        VerticalContainer container = new VerticalContainer();
        for (Node node : myNodes) container.add(node.createView(context));
        return container;
    }

    public int countChildren() {
        return myNodes.size();
    }

    public Node getChild(int index) {
        return myNodes.get(index);
    }

    public abstract Line createLine() throws InvalidHtmlDocumentException;
}
